﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BPM.Common;

namespace BPM.Entity
{
	/// <summary>
	/// 物料定义
	/// </summary>
	public class MaterialDefinition : BarcodeEntity
	{
		public MaterialDefinition()
		{
			this._Barcode = CreateReference<Barcode>();
			this._Creator = CreateReference<User>();
			this._Category = CreateReference<MaterialDefinitionCategory>();
		}

		#region 引用对象

		private ILazyEntityRef<Barcode> _Barcode;
		/// <summary>
		/// 物料定义的条码
		/// </summary>
		public Barcode Barcode
		{
			get
			{
				return this._Barcode.Entity;
			}
			set
			{
				this._Barcode.Entity = value;
			}
		}
		/// <summary>
		/// 物料定义的条码的Id
		/// </summary>
		public int BarcodeId
		{
			get
			{
				return this._Barcode.Id;
			}
			set
			{
				this._Barcode.Id = value;
			}
		}

		private ILazyEntityRef<User> _Creator;
		/// <summary>
		/// 创建人
		/// </summary>
		public User Creator
		{
			get
			{
				return this._Creator.Entity;
			}
			set
			{
				this._Creator.Entity = value;
			}
		}
		/// <summary>
		/// 创建人的Id
		/// </summary>
		public int CreatorId
		{
			get
			{
				return this._Creator.Id;
			}
			set
			{
				this._Creator.Id = value;
			}
		}

		private ILazyEntityRef<MaterialDefinitionCategory> _Category;
		/// <summary>
		/// 所属类别(最小的类别)
		/// </summary>
		public MaterialDefinitionCategory Category
		{
			get
			{
				return this._Category.Entity;
			}
			set
			{
				this._Category.Entity = value;
			}
		}
		/// <summary>
		/// 此物料所属的类别的Id
		/// </summary>
		public int CategoryId
		{
			get
			{
				return this._Category.Id;
			}
			set
			{
				this._Category.Id = value;
			}
		}

		#endregion

		/// <summary>
		/// 经理是否批准
		/// </summary>
		public bool IsApproved { get; set; }

		/// <summary>
		/// 当前的量
		/// </summary>
		public int CurrentAmount { get; set; }

		/// <summary>
		/// 物料定义名称
		/// </summary>
		public string Name { get; set; }
		/// <summary>
		/// 品牌
		/// </summary>
		public string Brand { get; set; }
		/// <summary>
		/// 价格
		/// </summary>
		public decimal Price { get; set; }
		/// <summary>
		/// 供应商名称
		/// </summary>
		public string SupplierName { get; set; }
		/// <summary>
		/// 联系人姓名
		/// </summary>
		public string ContactName { get; set; }
		/// <summary>
		/// 联系电话
		/// </summary>
		public string ContactPhone { get; set; }
		/// <summary>
		/// 其他联系方式
		/// </summary>
		public string OtherContact { get; set; }
		/// <summary>
		/// 供货周期
		/// </summary>
		public int DeliveryPeriod { get; set; }
		/// <summary>
		/// 供货周期单位(年,月,日,etc)
		/// </summary>
		public string DeliverPeriodUnit { get; set; }
		/// <summary>
		/// 付款方式
		/// </summary>
		public string PaymentMode { get; set; }
		/// <summary>
		/// 备注
		/// </summary>
		public string Remark { get; set; }
		/// <summary>
		/// 图片路径
		/// </summary>
		public string ImagePath { get; set; }

		public override Result Validate()
		{
			if (string.IsNullOrWhiteSpace(Name)) return "没有名称。";
			if (string.IsNullOrWhiteSpace(ImagePath)) return "没有图片。";
			if (DeliveryPeriod < 1 || DeliveryPeriod > 30) return "供货周期必须在1到30之间。";
			if (Price <= 0) return "价格不能为0。";
			if (CategoryId <= 0) return "还没有选择材料类别。";

			return base.Validate();
		}
	}
}
